﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RenChangYou.Common;
using System.Data;
using RenChangYou.BLL;
using DaoYou.Web.Guider.Account;

namespace DaoYou.Web.Account
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            try
            {
                if (txt_userName.Value.Length == 0 || txt_userName.Value.Length < 4 || txt_password.Value.Length == 0)
                {
                    Common.AlertMessage("请输入用户名或密码！"); 
                    return;
                }

                DY_User bll_User=new DY_User(); 
                using (DataTable dt = bll_User.UserLogin(txt_userName.Value.Trim(), txt_password.Value.Trim()))
                {
                    if (!Common.DtIsNullOrEmpty(dt))
                    {
                        PageHelper.Current.SetCookie(dt.Rows[0]["UserName"].ToString(), Convert.ToInt32(dt.Rows[0]["UserType"]));

                        Common.AlertMessage("登陆成功！");

                        Response.Redirect("~/Account/UserCenter.aspx", false);
                    }
                    else
                    { 
                        Common.AlertMessageAndRedirect("用户名或密码错误",ResolveUrl("~/Account/login.aspx"));
                    }
                }
               
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
